package com.concerneyes.health.healthView;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;

import com.concerneyes.R;
import com.concerneyes.health.EditOptometryData;
import com.concerneyes.health.Task.GlassManDataImpl;
import com.concerneyes.health.Task.GlassManDataListener;
import com.concerneyes.health.adapter.HisCarsAdapter;
import com.concerneyes.health.model.HealthDataModel;

import java.util.List;

import common.AbsBaseView;
import util.ActivityUtil;
import view.PullListView;
import view.listviewAnimation.listviewanimations.swinginadapters.prepared.SwingBottomInAnimationAdapter;

/**
 * Created by Administrator on 2017/6/29 0029.
 */

public class HisCardView extends AbsBaseView implements GlassManDataListener, AdapterView.OnItemClickListener {
    private PullListView plvHis;
    private HisCarsAdapter adapter;
    private Context context;
    private String manId;
    private GlassManDataImpl dataImpl;

    public HisCardView(Context context, String manId) {
        super(context);
        this.context = context;
        this.manId = manId;
        initView();
    }

    private void initView() {
        plvHis = (PullListView) findViewById(R.id.plv_his);
        adapter = new HisCarsAdapter(context);
        SwingBottomInAnimationAdapter swingBottomInAnimationAdapter = new SwingBottomInAnimationAdapter(adapter);
        swingBottomInAnimationAdapter.setAbsListView(plvHis);
        plvHis.setAdapter(swingBottomInAnimationAdapter);
        plvHis.setOnItemClickListener(this);
        dataImpl = new GlassManDataImpl(getActivity(), this);
        dataImpl.listGlassManData(manId);
    }

    @Override
    public int layoutResId() {
        return R.layout.view_his_card;
    }

    @Override
    public void loadData(Object data) {

    }

    @Override
    public boolean isEmpty() {
        return false;
    }

    @Override
    public void glassManDataListSuccess(List<HealthDataModel> model) {
        adapter.addData(model);
    }

    @Override
    public void glassManDataListFail() {

    }

    @Override
    public void deleteGlassManDataSuccess(List<HealthDataModel> model) {

    }

    @Override
    public void deleteGlassManDataFail() {

    }

    @Override
    public void addGlassManDataSuccess() {

    }

    @Override
    public void addGlassManDataFail() {

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        ActivityUtil.setIntentForEdit(context, EditOptometryData.class
                , manId, EditOptometryData.IS_SHOW, String.valueOf(adapter.getItem(position - 1).getId()));
    }
}
